<!DOCTYPE html>
<html>
    <head>
        <title> 数组 </title>
		<meta charset="utf-8" />
    </head>
    <body>

    </body>
    <script>
        //arr.length得到数组长度
        var arr = [1, 2, 3, 4, 5];
        console.log(arr.length);
        for(var i = 0;i < arr.length;i++){
            console.log(arr[i]);
        }

        //js中数组可以有动态的数组长度
        var arr1 = ["red","blue","green"];
        arr1[arr1.length] = "orange";
        console.log(arr1);

        //arr.sort()传入函数，数组元素排序
        //arr.reverse()对数组元素进行反序处理
        var arr4 = [3, 2, 5, 1, 9, 14];
        arr4 = arr4.sort(function(a, b){
            return a-b;
        });
        console.log(arr4.reverse());
        
        //写入五行四列表格，将帖子数组中数据填充到单元格中
        //创建二维数组
        var arr3 = [
            ["标题","a","写入五行四列表格，将帖子数组中数据填充到单元格中","2021-10-1"],
            ["标题","a","写入五行四列表格，将帖子数组中数据填充到单元格中","2021-10-1"],
            ["标题","a","写入五行四列表格，将帖子数组中数据填充到单元格中","2021-10-1"],
            ["标题","a","写入五行四列表格，将帖子数组中数据填充到单元格中","2021-10-1"],
            ["标题","a","写入五行四列表格，将帖子数组中数据填充到单元格中","2021-10-1"],
        ];
        var tbHeight = "500px";
        var tbWidth = "800px";
        documemt.write("<table border='1' height='"+tbHeight+"' width='"+tbWidth+"'>");
        function createList(arr3){
           document.write('<table border="1" cellspacing="0">');
           for (var i = 0; i < arr3.length; i++) {
               document.write("<tr>");
               for (var j = 0; j < arr3[i].length; j++){
                   if(j == 2)
                   arr3[i][j] = arr[i][j].slice(0, 5) + "......";
                    document.write("<td>");
                        document.write(arr3[i][j]);
                    document.write("</td>");
                }
                document.write("</tr>");
            }
       }
       createList(arr3);
       document.write("</table>");

      
    </script>
</html>